<?php
/**
 * Registration request object
 * 
 * @package stanza.iq.register
 */
class Zend_Jabber_Stanza_Response_Iq_Register_Result extends Zend_Jabber_Stanza_Response_Iq_Register_Abstract {
    /**
     * Get registration instructions from response when requesting registration fields
     * 
     * @return string 
     */
    public function getInstructions() {
        if($this->getRequest()->getType() != 'get') return false; 
        return $this->dom->getElementsByTagName("instructions")->item(0)->nodeValue;
    }
    
    /**
     * Get array of required fields when requesting registration information
     * 
     * @return array
     */
    public function getRequiredFieldsArray() {
        if($this->getRequest()->getType() != 'get') return false; 
        $requiredFields = array();
        foreach($this->dom->getElementsByTagName("query")->item(0)->getElementsByTagName("*") as $node) {
            if(!in_array($node->tagName, array('instructions', 'x'))) {
                $requiredFields[] = $node->tagName;
            }
        }
        
        return $requiredFields;
    }
    
    /**
     * Get additional registration information
     * 
     * @param array
     */
    public function getX() {
        if($this->getRequest()->getType() != 'get') return false; 
        
        $x = array();
        if($xNode = $this->dom->getElementsByTagName("x")->item(0)) {
	        foreach($xNode->childNodes as $tag) {
	            $x[$tag->tagName] = $tag->nodeValue;
	        }
        }
        
        return $x;
    }
}
?>